# class Cat:
#     __name='小明' #加俩__表示私有
#     age=16
#
#     def __init__(self,age):
#         self.age =age
#     def print(self):
#         print('私有方法...')
#         print(self.age)
#     def getName(self):
#         return self.__name
#
# cat=Cat(11)
# cat.print()
# cat1=Cat(12)
# cat1.print()
# print(cat.getName())
#
#
# def CarMini(Cat):
#     size=11
#     def __init__(self):
#         Cat.__init__(10)
#         self.size=size
#
#     def printSize(self):
#         print(self.size)
#
# car2=CarMini(111)
# car2.printSize()

class ParentClass:
    # 父类的初始化方法
    def __init__(self, name):
        self.name = name

    def greet(self):
        print(f"Hello, I am {self.name}")


# 子类继承 ParentClass
class ChildClass(ParentClass):
    def __init__(self, name, age):
        # 调用父类的构造方法
        super().__init__(name)
        self.age = age

    # 重写父类的方法
    def greet(self):
        print(f"Hello, I am {self.name} and I am {self.age} years old.")


# 创建实例
parent = ParentClass("ParentName")
parent.greet()  # 输出：Hello, I am ParentName

child = ChildClass("ChildName", 10)
child.greet()  # 输出：Hello, I am ChildName and I am 10 years old.
